import java.util.ArrayList;
import java.util.Scanner;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;

public class Cozinha extends JFrame{

	private static ArrayList<Pedido> pedidos = new ArrayList<Pedido>();
	 // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton atualizaListaButton;
    private javax.swing.JButton gerenciaPedidoButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel listaPedidosLabel;
    private javax.swing.JList listaPedidosList;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables

    private GerenciaPedidoFrame gerenciaFrame = new GerenciaPedidoFrame();
    private DefaultListModel modeloPedidos = new DefaultListModel();
    //private ArrayList<Pedidos> listaPedidos = new ArrayList<Pedidos>();
	
    public Cozinha() {
		initComponents();
	}
    
	private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        atualizaListaButton = new javax.swing.JButton();
        gerenciaPedidoButton = new javax.swing.JButton();
        listaPedidosLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaPedidosList = new javax.swing.JList();
        
        super.setDefaultCloseOperation(EXIT_ON_CLOSE);

        titleLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        titleLabel.setText("COZINHA");

        atualizaListaButton.setText("Atualizar Lista");
        atualizaListaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaListaButtonActionPerformed(evt);
            }
        });

        gerenciaPedidoButton.setText("Gerenciar Pedido");
        gerenciaPedidoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gerenciaPedidoButtonActionPerformed(evt);
            }
        });

        listaPedidosLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        listaPedidosLabel.setText("Lista de Pedidos");

        listaPedidosList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(listaPedidosList);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(167, 167, 167)
                .addComponent(titleLabel)
                .addContainerGap(171, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(81, Short.MAX_VALUE)
                .addComponent(atualizaListaButton)
                .addGap(54, 54, 54)
                .addComponent(gerenciaPedidoButton)
                .addGap(60, 60, 60))
            .addGroup(layout.createSequentialGroup()
                .addGap(154, 154, 154)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(listaPedidosLabel))
                .addContainerGap(153, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleLabel)
                .addGap(18, 18, 18)
                .addComponent(listaPedidosLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(atualizaListaButton)
                    .addComponent(gerenciaPedidoButton))
                .addGap(25, 25, 25))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void atualizaListaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaListaButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_atualizaListaButtonActionPerformed

    private void gerenciaPedidoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gerenciaPedidoButtonActionPerformed
        gerenciaFrame.setVisible(true);
        super.setVisible(false);
    }//GEN-LAST:event_gerenciaPedidoButtonActionPerformed
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Cozinha cozinha = new Cozinha();
		cozinha.setVisible(true);
		// TODO Auto-generated method stub
			try{
				Registry registry = LocateRegistry.getRegistry();
				InterfaceCozinha stub = (InterfaceCozinha) registry.lookup("cozinha");
			
			Scanner input = new Scanner(System.in);
			
			while(true){
				System.out.println("COZINHA");
				System.out.println("OPCOES");
				System.out.println("OP 1 Receber Pedidos");
				System.out.println("OP 2 Encerrar Pedidos");
				
				int op = input.nextInt();
				
				if(op == 1){
					
					//stub.receberPedidos(pedidos);
					//for(int i=0; i<pedidos.size(); i++)
					//System.out.printf("\n%f, %d\n", pedidos.get(i).getValor(), pedidos.get(i).getNumero());
						
				} else if(op == 2){
					System.out.println("Entre com o número do pedido:");
					int pedido = input.nextInt();
					for(int i = 0; i < pedidos.size(); i++){
						if(pedido == pedidos.get(i).getNumero()){
							//stub.fecharPedido(pedidos.get(i));
							break;
						}
					}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}